package com.app.news;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView textView;
    int time=3;
    Handler handler=new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
//            super.handleMessage(msg);
            if (msg.what==1){
                time--;
                if (time==0){
                    Intent intent=new Intent(MainActivity.this,IndexActivity.class);
                    startActivity(intent);
                }else {
                    textView.setText(time+"");
                    handler.sendEmptyMessageDelayed(1,1000);
                }
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();
    }
    private  void initView(){
        textView = findViewById(R.id.main_tv);
        handler.sendEmptyMessageDelayed(1,1000);
    }
    private  void initData(){}
    private  void initEvent(){}
}
